<script>
export default {
  name: 'Login',
  data () {
    return {
      user: {
        username: '',
        password: ''
      },
      ruleUser: {
        username: [
          { required: true, message: '请填写用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请填写密码', trigger: 'blur' }
        ]
      },
      loading: false,
      redirect: '/index.html'
    }
  },
  created: function () {
  },
  watch: {
  },
  methods: {
    handleSubmit () {
      let self = this
      this.$refs['user'].validate(function (valid) {
        if (valid) {
          self.loading = true
          setTimeout(() => {
            self.loading = false
            location.href = self.redirect
          }, 3000)
        } else {
          self.$message.error('用户名/密码不能为空')
        }
      })
    }
  }
}
</script>

<template>
  <div class="login-container-wrapper">
    <div class="login-container">
      <div class="title">欢迎使用医院统一信息平台</div>
      <el-form ref="user" :model="user" :rules="ruleUser">
        <el-form-item prop="username">
          <el-input v-model="user.username" placeholder="用户名" @keyup.enter.native="handleSubmit"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="user.password" placeholder="密码" @keyup.enter.native="handleSubmit"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click.native.prevent="handleSubmit" @keyup.enter.native="handleSubmit" :loading="loading" style="width: 100%;">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login-container-wrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 1000;
}
.login-container-wrapper::after {
  content: "";
  display: inline-block;
  height: 100%;
  width: 0;
  vertical-align: middle;
}
.login-container {
  display: inline-block;
  vertical-align: middle;
  width: 420px;
  padding-bottom: 10px;
  background-color: #fff;
  border-radius: 4px;
  -ms-border-radius: 4px;
  -moz-border-radius: 4px;
  -o-border-radius: 4px;
  -webkit-border-radius: 4px;
  border: 1px solid #ebeef5;
  font-size: 18px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  -ms-box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  -moz-box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  -o-box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  -webkit-box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  text-align: left;
  overflow: hidden;
  backface-visibility: hidden;
  background-clip: padding-box;
  box-sizing: border-box;
  -ms-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  padding: 35px 35px 15px 35px;
}
.title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}
</style>
